<?php

/**
 * This is the model class for table "organization_settings".
 *
 * The followings are the available columns in table 'organization_settings':
 * @property integer $organization_id
 * @property integer $amount_decimal_place
 * @property integer $quantity_decimal_place
 */
class OrganizationSettings extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return OrganizationSettings the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'organization_settings';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('organization_id', 'required'),
			array('organization_id, amount_decimal_place, quantity_decimal_place', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('organization_id, amount_decimal_place, quantity_decimal_place', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'organization_id' => 'Organization',
			'amount_decimal_place' => 'Amount Decimal Place',
			'quantity_decimal_place' => 'Quantity Decimal Place',
		);
	}
	
	public function behaviors()
	{ 
		return array( 'LoggableBehavior'=> 'application.modules.auditTrail.behaviors.LoggableBehavior', ); 
	}
	
	public function getInventoryMethod($organizationId)
	{
		$method = self::model()->find(array(
				'select'=>'inventory_method',
				'condition'=>'organization_id=:organizationId',
				'params'=>array(':organizationId'=>$organizationId)));
		
		return $method;
	}

}